package es.ats.codington.festival.services;

import java.io.FileNotFoundException;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import es.ats.codington.festival.daos.ManagerDAO;
import es.ats.codington.festival.domain.Imagen;
import es.ats.codington.festival.domain.Place;

import es.ats.codington.festival.exceptions.ServiceException;

import es.ats.codington.festival.interfaces.daos.IPlaceDAO;
import es.ats.codington.festival.interfaces.services.IPlaceService;

/**
 * 
 * @author Codington_RED
 *
 */
public class PlaceService implements IPlaceService{
	
	
	private IPlaceDAO placeDAO;

	public PlaceService(){
		ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");  
		ManagerDAO daoManager = (ManagerDAO) ctx.getBean("daoManager");
		this.placeDAO = daoManager.getPlaceDAO();
	}
	/**
	 * method that retrieves the place throught its ID
	 * @param idPlace
	 * @return placeDAO.getPlace(idPlace)
	 * @throws ServiceException
	 */
	@Override
	public Place getPlace(int idPlace) throws ServiceException {
		
		return placeDAO.getPlace(idPlace);
	}
	
	/**
	 * obtains a image from the database
	 * @param route
	 * @param name
	 * @return placeDAO.imageSpring(route, name)
	 * @throws ServiceException
	 * @throws FileNotFoundException
	 */
	@Override
	public Imagen getImage(String route, String name) throws ServiceException, FileNotFoundException {
		
		return placeDAO.imageSpring(route, name);
		
	}
	
	/**
	 * method that obtains a list with all places registered into the system
	 * @return placeDAO.showAllPlaces()
	 * @throws ServiceException
	 */
	@Override
	 public List<Place> getAllPlaces() throws ServiceException {
		
			return placeDAO.showAllPlaces();
			
	 }
	
	/**
	 * method that modifies all the information about a determined place 
	 * @param place
	 * @return placeDAO.updatePlace(place)
	 * @throws ServiceException
	 */
	@Override
    public int updatePlace(Place place) throws ServiceException {
	
		return placeDAO.updatePlace(place);
		
    }
	
	/**
	 * method that inserts a place into the database
	 * @param place
	 * @param typePlace
	 * @return placeDAO.insertPlace(place, typePlace)
	 * @throws ServiceException
	 */
	@Override
    public boolean insertPlace(Place place, String typePlace) throws ServiceException{
		
		return placeDAO.insertPlace(place, typePlace);
	
	}

}

